#import "textundo.h"

#define PASTE_OPERATION NXLocalStringFromTable("Operations", "Paste", NULL, "The operation of getting something from the Pasteboard and inserting into the document.")

@implementation PasteTextChange

/*
 * This class calculates how many characters were pasted by looking at
 * the length of the original selection, and the length of the text object
 * before the paste. 
 */

- initView:aView
{
    [super initView:aView name:PASTE_OPERATION];
    return self;
}

- saveBeforeChange
{
    NXSelPt start, end;

    [super saveBeforeChange];

    [textView getSel:&start :&end];
    textLength = [textView textLength];
    selectionStart = start.cp;
    selectionLength = end.cp - start.cp;

    return self;
}

- saveAfterChange
{
    int charsPasted;

    charsPasted = [textView textLength] - (textLength - selectionLength);
    newSel = [[TextSelection alloc] initText:textView
	                               start:selectionStart
	                                 end:selectionStart + charsPasted];
    [newSel capture];
    return self;
}

@end
